<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="/books/css/add.css"/>
    <script type="text/javascript" src="/books/js/jquery.1.9.1.js" ></script>
    <script type="text/javascript" src="/plan/js/layer.js" ></script>
    <script type="text/javascript" src="/books/js/iScroll.js" ></script>
    <script type="text/javascript" src="/books/js/Mdate.js" ></script>
	<script type="text/javascript" src="/books/js/mobileSelect.js"></script>
	<link rel="stylesheet" type="text/css" href="/books/css/mobileSelect.css"/>
	<script type="text/javascript" src="/books/js/rem.js" ></script>
    <title>日记账</title>
</head>
<style>
	.session2{display: inline-block;margin-top: 0.1rem;font-size: 0.3rem;}
	.caigou{font-size: 0.3rem;}
	.bitian0{margin-right: 0.2rem;}
	.bitian{margin-top: 0.13rem;}
	.hide{display: none}
</style>
<body>
<form id="form2" action="" enctype="multipart/form-data"  method="post">
<ul class="order_money" style="padding: 0 0.3rem;background: #fff;">
    <li>
    		<span class="num fontchange">凭证单号</span>
    		<span class="bitian0">必填</span>
    		<input type="text" class="inputchange" id="number" value="" />
    </li>
    {if !$ids}
    <li>
		<span class="week">开会周次</span><span class="jt"></span>
		<div id="trigger4" class="trigger4" style="display: inline-block;width: 96%;margin-top: 0.1rem;">
		 	<span class="must">必填</span>
		</div>
		 <input type="hidden" name="" id="week" value="" />								
	</li>
	{else}
	 <input type="hidden" name="" id="week" value="{$ids}" />	
	{/if}
    <li>
		<span class="time">日期</span><span class="jt"></span>
		<div id="trigger7" class="trigger7" style="display: inline-block;width: 96%;margin-top: 0.1rem;">
		 	<span class="must">必填</span>
		</div>
		 <input type="hidden" name="day" id="day" value="" />								
	</li>

    <li>
		<span class="type">收支类型</span><span class="jt"></span>
		<div id="trigger5" class="trigger5" style="display: inline-block;width: 96%;margin-top: 0.1rem;">
		 	<span class="must">必填</span>
		</div>
		 <input type="hidden" name="" id="pay_type" value="" />								
	</li>
	<li class="hide">
		<span class="fee">费用项目</span><span class="jt"></span>
		<div id="trigger6" class="trigger6" style="display: inline-block;width: 96%;margin-top: 0.1rem;">
		 	<span class="must">必填</span>
		</div>
		 <input type="hidden" name="" id="cost_id" value="" />								
	</li>
	<li style="height: 2.5rem;overflow: hidden;">
		<p class="title fontchange">费用摘要</p>
		<span class="bitian0">必填</span>
        <textarea class="inputchange beizhu" value="" id="abstract"></textarea>
    </li>
	<li>
    		<span class="num fontchange">金额</span>
    		<span class="bitian0">必填</span>
    		<input type="number" class="inputchange" id="price" value="" />
    </li>
	<li style="height: 2.5rem;overflow: hidden;">
		<p class="title fontchange">单据备注</p>
        <textarea class="inputchange beizhu" value="" id="desc"></textarea>
    </li>
</ul>
<div class="button">
	<div class="close">删除</div>
	<div class="continue"><input class="pay" type="button" name="" id="" value="保存" /></div>
</div>
<div class="button">
	<input class="pay" type="button" name="" id="" value="保存" />
</div>
</form>
<script>
 {if !$ids}
 var url  = "/index/books/view/ids/";
 {else}
 var url  = "/index/plan/public_view/type/Books/ids/";
 {/if}
//提交表单
$(function(){
	$('.pay').click(function(){
		var number = $('#number').val();
		var week = $('#week').val();
		var day = $('#day').val();
		var price = $('#price').val();
		var pay_type = $('#pay_type').val();
		var cost_id = $('#cost_id').val();
		var desc = $('#desc').val();
		var abstract = $('#abstract').val();
		if(number == ''||number == null){
				layer.open({
				content:'请输入凭证单号' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}
		if(week == ''||week == null){
				layer.open({
				content:'请选择开会周次' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}
		if(day == ''||day == null){
			layer.open({
				content:'请选择单据日期' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}	
		if(pay_type == ''||pay_type == null){
				layer.open({
				content:'请选择收支类型' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}
		if((cost_id == ''||cost_id == null)&& pay_type == 2){
				layer.open({
				content:'请选择费用项目' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}
		if(abstract == ''||abstract == null){
			layer.open({
				content:'请填写费用摘要' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}
		if(price == ''||price == null){
				layer.open({
				content:'请输入金额' ,
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false
		}
	
		layer.open({type: 2});
		$.ajax({
		  type: 'post',
		  url:"/index/books/add" ,
		  data:{number:number,day:day,extract_week:week,price:price,pay_type:pay_type,cost_id:cost_id,abstract:abstract,desc:desc},
		  dataType: "json",
		  success: function(data){
		    if(data.code){
			  		 layer.open({
						content:'操作成功' ,
						skin: 'msg',
						time: 2 //2秒后自动关闭
					});
			  		 setTimeout(function () {
						window.location.href = url+data.data;
					},2000);
			  	}else{
			  		  layer.open({
						content:'操作失败,请刷新重试' ,
						skin: 'msg',
						time: 2 //2秒后自动关闭
					});
			  	}
	  
		   }
		 });
	 });
});
</script>
<script>
$(function(){
	//先判断input是否有内容
	if($('.inputchange').val() != ''){
		$(this).siblings('.bitian0').hide();
		$(this).siblings('.fontchange').css('font-size','0.2rem');
	}else{
		$(this).siblings('.bitian0').show();
		$(this).siblings('.fontchange').css('font-size','0.32rem');
	}
	//输入时字体变化
	$('.inputchange').keyup(function(){
		if($('.inputchange').val() != ''){
			$(this).siblings('.bitian0').hide();
			$(this).siblings('.fontchange').css('font-size','0.2rem');
		}else{
			$(this).siblings('.bitian0').show();
			$(this).siblings('.fontchange').css('font-size','0.32rem');
		}
	});
});
</script>
<script>
	var arr = [];
	var DefaultsDate = {$DefaultsDate};
	var DefaultsDateW = {$DefaultsDateW};
	var department = {$books_auth['department']};
  	$.ajax({
	  url: '/api/ajax/year_week',
	  type: 'post',
	  async: false,
	  data:{type:3,year:DefaultsDate,week_text:DefaultsDateW,department:department},
	  success: function (year) {
	  	console.log(year);
	  	   arr = year.data.data;
	  	   DefaultsDate = year.data.year_more;
	  	   DefaultsDateW = year.data.week_more;
	  	 
	  }
	});
	//周次联动
	var mobileSelect4 = new MobileSelect({
	    trigger: '#trigger4',
	    title: '周次选择',
	    wheels: [{data:arr}],
	    position:[DefaultsDate,DefaultsDateW],
		 transitionEnd:function(indexArr, data){
		        
		 },
		 callback:function(indexArr, data){
		    $('#week').val(data[1].value);
		    $('.week').css('font-size','0.2rem');
		 }
	});
	
	//收支类型
	var mobileSelect5 = new MobileSelect({
	    trigger: '#trigger5',
	    title: '收支类型',
	    wheels: [{data:[
	    					{
                            value:'1',
                            name:'收入'
                        },
                        {
                            value:'2',
                            name:'支出'
                        }
	    			]}],
		 transitionEnd:function(indexArr, data){
		        
		 },
		 callback:function(indexArr, data){
		    $('#pay_type').val(data[0].value);
		    $('.type').css('font-size','0.2rem');
		    if($('#pay_type').val() == 1){
		    		$('.hide').hide();
		    }else{
		    		$('.hide').show();
		    }
		 }
	});
	//费用项目
	var mobileSelect6 = new MobileSelect({
	    trigger: '#trigger6',
	    title: '费用项目',
	    wheels: [{data:[
	    					{
                            id:'1',
                            value:'',
                            childs:[
                                {id:'A1',value:''},
                            ]
                        },
	    			]}],
		 transitionEnd:function(indexArr, data){
		        
		 },
		 callback:function(indexArr, data){
		 	console.log(data)
		    $('#cost_id').val(data[0].value);
		    $('.fee').css('font-size','0.2rem');
		 }
	});
	$.ajax({
        type: "post",
        url: "/api/ajax/cost?type=1",
        dataType: "json",
        success: function(res){
            mobileSelect6.updateWheels(res.data);
        }
  	});
  	var DefaultsDateD = {$DefaultsDateD};
  	//日期
	var mobileSelect7 = new MobileSelect({
	    trigger: '#trigger7',
	    title: '日期',
	    wheels: [{data:[
	    					{
                            value:'1',
                            name:'星期一'
                        },
                        {
                            value:'2',
                            name:'星期二'
                        },
                        {
                            value:'3',
                            name:'星期三'
                        },
                        {
                            value:'4',
                            name:'星期四'
                        },
                        {
                            value:'5',
                            name:'星期五'
                        },
                        {
                            value:'6',
                            name:'星期六'
                        },
                        {
                            value:'7',
                            name:'星期日'
                        },
	    			]}],
	     position:[DefaultsDateD],
		 transitionEnd:function(indexArr, data){
		        
		 },
		 callback:function(indexArr, data){
		    $('#day').val(data[0].value);
		    $('.time').css('font-size','0.2rem');
		 }
	});
</script>
</body>
</html>
